﻿@using HPIT.RentHouse.DTO

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    var perList = ViewBag.perList as List<PermissionDTO>;
}

<article class="cl pd-20">
    <form action="@Url.Action("Add_Role","Roles")" method="post" class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名字：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="Name" name="Name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色权限：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <dl class="permission-list">
                    <dt><label>选择权限</label></dt>
                    <dd>
                        <dl class="cl permission-list2">
                            @foreach (PermissionDTO permission in perList)
                            {
                                <dt>
                                    <label>
                                        <input type="checkbox" name="PermissionIds" value="@permission.Id"/>
                                        @permission.Description
                                    </label>
                                </dt>
                            }
                        </dl>
                    </dd>
                </dl>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
@section footScript{
    <script type="text/javascript">
        $(function () {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form-admin-add").validate({
                rules: {
                    Name: {
                        required: true,
                        minlength: 1,
                        maxlength: 16
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        success: function (data) {
                            console.log(data)
                            if (data.State == 1) {
                                parent.location.reload();
                            } else {
                                layer.msg(data.ErrorMessage, { icon: 2 })
                            }
                        }
                    })
                }
            })
        })
    </script>
}